<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="./css/home_new_index_reform6.css">
</head>

<body>

    <div class="yaowen-list">

    </div>
</body>
<script>
    /*要闻三条*/
    var readId = [];
    if(oVal.configData.THS_MZ_KEY || oVal.configData.THS_MZ_KEY == "0"){
        //旧版资讯推荐
        getOldYaoWenInfo()
    }else{
        getYaoWenThreeInfo();
    }
    oVal.infoOffset_yw = "0";//取接口返回的字段
    function getYaoWenThreeInfo() {
        var append = "1_0_0_1";
        var oSendData = {
            action: '31020',
            param:JSON.stringify({
                /*"listId":"headline",
                "append":append*/
                "accessKey":"e6ce431bd537718a",
                "infoOffset":oVal.infoOffset_yw,//当前已遍历查询的资讯页数，默认为 0
                "page":oVal.ywPageNum - 1,
            }),
            ReqLinkType: '2'
        };
        $.getData({
            oSendData: oSendData,
            copyIsArray: false,
            isload: false,
            fnSuccess: function (data) {
                console.log(data,JSON.parse(data.BINDATA));
                var sHtml = '';
                if (data.BINDATA) {
                    // var _result = JSON.parse(data.BINDATA).data.pageItems;
                    // oVal.ywNextPage = JSON.parse(data.BINDATA).data.nextPage;
                    var _result = JSON.parse(data.BINDATA).data;
                    oVal.infoOffset_yw = JSON.parse(data.BINDATA).infoOffset;
                    if(_result.length > 0){
                        oVal.ywNextPage = JSON.parse(data.BINDATA).hasNext;
                        for (var i = 0; i < _result.length; i++) {
                            var obj = {};
                            obj.id = _result[i].itemId;//id
                            //obj.ctime = _result[i].ctime;//时间，日期
                            obj.ctime = _result[i].time;//时间，日期
                            obj.imgUrl = _result[i].imgUrl;//图片
                            obj.source = _result[i].source;//来源
                            obj.title = _result[i].title;//标题
                            obj.copyright = _result[i].copyright;//有无版权
                            obj.url = _result[i].url;//无版权时的三方地址

                            if(obj.copyright && obj.copyright == "1"){
                                sHtml += loadDOM_TT(obj);
                            }
                        }
                    }
                }
                $('.yaowen-list').html(sHtml);
                pageUrl();
            },
            oConfig:function (error) {
                console.log(error)
            }
        });
    }
    function loadDOM_TT(data){
        var readClass='';
        /*if(readId.toString().indexOf(data.id) > -1){
            readClass='zx-read-name';
        }*/
        var newDate = dateStr(formatDate(data.ctime));
        //var newDate = formatDateHM(data.ctime);
        var sHtml = '<li class="zx-list" data-copyright="' + data.copyright + '" data-url="' + data.url + '" data-id="' + data.id + '"  data-time="' + formatDate(data.ctime) + '"  data-title="' + data.title + '"  data-source="' + data.source + '">'
            /*+'<img  src="'+ data.imgUrl +'" onload=this.nextSibling.style.display="none"; class="img">'
            +'<img  src="./img/moren.png" class="none">'*/
            + '<p class="zx-name '+ readClass + '">' + data.title + '</p><p class="zx-foot">'
            + '<span class="zx-date">' + newDate + '</span>'
            + '<span class="zx-media" style="float: right;padding-right: 0.1rem;">' + data.source + '</span></p>'
            + '</li>';
        return sHtml;
    }
    function formatDate(timestamp) {
        var date = new Date(timestamp*1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var Y = date.getFullYear(),
            M = (date.getMonth()+1 < 10 ? (date.getMonth()+1) : date.getMonth()+1),
            D = date.getDate(),
            h = date.getHours(),
            m = date.getMinutes(),
            s = date.getSeconds();
        M = M < 10 ? "0"+ M : M;
        D = D < 10 ? "0"+ D : D;
        h = h < 10 ? "0"+ h : h;
        m = m < 10 ? "0"+ m : m;
        s = s < 10 ? "0"+ s : s;
        return Y+"-"+M+"-"+D+" "+h+":"+m+":"+s;
    }
    function formatDateHM(timestamp) {
        var date = new Date(timestamp*1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var Y = date.getFullYear(),
            M = (date.getMonth()+1 < 10 ? (date.getMonth()+1) : date.getMonth()+1),
            D = date.getDate(),
            h = date.getHours(),
            m = date.getMinutes(),
            s = date.getSeconds();
        M = M < 10 ? "0"+ M : M;
        D = D < 10 ? "0"+ D : D;
        h = h < 10 ? "0"+ h : h;
        m = m < 10 ? "0"+ m : m;
        s = s < 10 ? "0"+ s : s;
        return h+":"+m;
    }
    function dateStr(date){
        //console.log(date)
        var nowDate = new Date();
        var time=nowDate.getTime();
        var nowyear = nowDate.getFullYear();
        var year = date.substr(0,4);
        var month = Number(date.substr(5,2));
        var day = Number(date.substr(8,2));
        var hour = Number(date.substr(11,2));
        var minute = Number(date.substr(14,2));
        var second = Number(date.substr(17,2));
        var newDate = new Date(year,month-1,day,hour,minute,second).getTime();
        time=parseInt((time-newDate)/1000);
        var s;
        if(time<60*5){//五分钟内
            return '刚刚';
        }else if((time<60*60)&&(time>=60*5)){//超过十分钟少于1小时
            s = Math.floor(time/60);
            return  s+"分钟前";
        }else if((time<60*60*24)&&(time>=60*60)){ //超过1小时少于24小时
            s = Math.floor(time/60/60);
            return  s+"小时前";
        }else if((time<60*60*24*3)&&(time>=60*60*24)){ //超过1天少于3天内
            s = Math.floor(time/60/60/24);
            return s+"天前";
        }else{ //超过3天
            if (year == nowyear) {
                return date.substr(5,5);
            }else{
                return date.split(" ")[0];
            }
        }
    }
    function pageUrl(){
        var action='read.txt';
        $('.zx-list').off().on('click', function(){
            var sId = $(this).attr('data-id'),
                time = $(this).attr('data-time'),
                source = $(this).attr('data-source'),
                jumpurl = $(this).attr('data-url'),
                copyright = $(this).attr('data-copyright'),
                title = $(this).attr('data-title');
            var obj = {
                'url':'/zx2/zx_zxxq.html?type=ths&id=' + sId + '&time='+ encodeURIComponent(time) + '&source='+ encodeURIComponent(source)
            };
            T.saveMapMesg({'THSPAGETITLE': title}, function () {});
            var oSend = {url:obj.url};

            // $(this).find(".zx-name").addClass('zx-read-name');
            if(readId.toString().indexOf(sId) == -1){
                readId.push(sId);
            }
            T.saveFileMesg(readId,action,function(oData){
                T.readFileMesg(action,function(oData){
                    if(copyright == "1"){
                        TZT.fn.action10061(oSend);
                    }else{
                        TZT.fn.action10061({url:jumpurl});
                    }
                })
            });
        });
    }

    //旧版资讯推荐
    function getOldYaoWenInfo(){  //上拉加载的回调
        var oSendData = {
            'action': '46118',//东财转开利，接口做调整
            'nPage': "1",
            'maxcount': "20",
            'menu_id': '20001',/*20024,20023,20025,20017*/
            ReqLinkType: '2'
        };
        $.getData({
            oSendData: oSendData,
            copyIsArray: false,
            isload: false,
            fnSuccess: function (data) {
                var aGrid = data.GRID0;
                var sHtml = '';
                if (aGrid) {
                    for (var i = 0; i < aGrid.length; i++) {
                        var _result = aGrid[i].split('|');
                        var obj = {};
                        obj.id = _result[data['IDINDEX']];//id
                        obj.ctime = _result[data['DATESINDEX']];//时间，日期
                        obj.imgUrl = _result[data['PICURLINDEX']];//图片
                        obj.source = _result[data['MEDIAINDEX']];//来源
                        obj.title = _result[data['INFOTITLEINDEX']];//标题

                        sHtml += loadDOM_TT_Old(obj);
                    }
                }

                if(aGrid.length >=20){
                    oVal.ywNextPage = true;
                }else{
                    oVal.ywNextPage = false;
                }

                $('.yaowen-list').html(sHtml);
                pageUrlOld();
            },
            oConfig:function(){

            }
        });
    }
    function loadDOM_TT_Old(data){
        var readClass='';
        /*if(readId.toString().indexOf(data.id) > -1){
            readClass='zx-read-name';
        }*/
        var newDate = dateStr(data.ctime);
        var sHtml = '<li class="zx-list" data-id="' + data.id + '">'
            /*+'<img  src="'+ data.imgUrl +'" onload=this.nextSibling.style.display="none"; class="img">'
            +'<img  src="./img/moren.png" class="none">'*/
            + '<p class="zx-name '+ readClass + '">' + data.title + '</p><p class="zx-foot">'
            + '<span class="zx-date">' + newDate + '</span>'
            + '<span class="zx-media" style="float: right;padding-right: 0.1rem;">' + data.source + '</span></p>'
            + '</li>';
        return sHtml;
    }
    function pageUrlOld() {
        var action='read.txt';
        $('.zx-list').off().on('click', function(){
            var imgsrc = encodeURIComponent($(this).find("img").attr("src"));
            var sId = $(this).attr('data-id');
            var obj = {
                'url':'/zx2/zx_zxxq.html?id=' + sId + '&&type=tuijian&&imgsrc='+imgsrc
            };
            $(this).find(".zx-name").addClass('zx-read-name');
            if(readId.toString().indexOf(sId) == -1){
                readId.push(sId);
            }
            T.saveFileMesg(readId,action,function(oData){
                T.readFileMesg(action,function(oData){
                    var oSend = {url:obj.url};
                    oSend.secondtype = '98';
                    oSend.secondtext = 'tzt_zx.png';
                    oSend.secondjsfuncname = 'tztPageSecodeFun()';
                    oSend.TitleSkinType = 1;
                    TZT.fn.action10061(oSend);
                })
            });
        });
    }

    /*要闻其他数据*/
    oVal.ywPageNum = 1;
    oVal.loadYWFlag = true;
    function getYaoWenOtherInfo() {
        var append = "1_0_0_"+ oVal.ywPageNum;
        var oSendData = {
            action: '31020',
            param:JSON.stringify({
                "accessKey":"e6ce431bd537718a",
                /*"listId":"headline",
                "append":append*/
                "infoOffset":oVal.infoOffset,//当前已遍历查询的资讯页数，默认为 0
                "page":oVal.ywPageNum - 1,
            }),
            ReqLinkType: '2'
        };
        $.getData({
            oSendData: oSendData,
            copyIsArray: false,
            isload: false,
            fnSuccess: function (data) {
                console.log(data,JSON.parse(data.BINDATA));
                var sHtml = '';
                if (data.BINDATA) {
                    // var _result = JSON.parse(data.BINDATA).data.pageItems;
                    // oVal.ywNextPage = JSON.parse(data.BINDATA).data.nextPage;
                    var _result = JSON.parse(data.BINDATA).data;
                    oVal.infoOffset = JSON.parse(data.BINDATA).infoOffset;
                    if(_result.length > 0){
                        oVal.ywNextPage = JSON.parse(data.BINDATA).hasNext;
                        for (var i = 0; i < _result.length; i++) {
                            var obj = {};
                            obj.id = _result[i].itemId;//id
                            //obj.ctime = _result[i].ctime;//时间，日期
                            obj.ctime = _result[i].time;//时间，日期
                            obj.imgUrl = _result[i].imgUrl;//图片
                            obj.source = _result[i].source;//来源
                            obj.title = _result[i].title;//标题
                            obj.copyright = _result[i].copyright;//有无版权
                            obj.url = _result[i].url;//无版权时的三方地址
                            if(obj.copyright && obj.copyright == "1"){
                                sHtml += loadDOM_TT(obj);
                            }
                        }
                        $('.yaowen-list').append(sHtml);
                        pageUrl();
                        oVal.loadYWFlag = true;
                    }
                }

            },oConfig:function(){

            }
        });
    }

    //旧版资讯推荐
    function getOldYaoWenOtherInfo() {
        var oSendData = {
            'action': '46118',//东财转开利，接口做调整
            'nPage': oVal.ywPageNum,
            'maxcount': "20",
            'menu_id': '20001',/*20024,20023,20025,20017*/
            ReqLinkType: '2'
        };
        $.getData({
            oSendData: oSendData,
            copyIsArray: false,
            isload: false,
            fnSuccess: function (data) {
                var aGrid = data.GRID0;
                var sHtml = '';
                if (aGrid) {
                    for (var i = 0; i < aGrid.length; i++) {
                        var _result = aGrid[i].split('|');
                        var obj = {};
                        obj.id = _result[data['IDINDEX']];//id
                        obj.ctime = _result[data['DATESINDEX']];//时间，日期
                        obj.imgUrl = _result[data['PICURLINDEX']];//图片
                        obj.source = _result[data['MEDIAINDEX']];//来源
                        obj.title = _result[data['INFOTITLEINDEX']];//标题

                        sHtml += loadDOM_TT_Old(obj);
                    }
                }

                if(aGrid.length >=20){
                    oVal.ywNextPage = true;
                }else{
                    oVal.ywNextPage = false;
                }

                $('.yaowen-list').append(sHtml);
                pageUrlOld();
                oVal.loadYWFlag = true;
            },
            oConfig:function(){

            }
        });
    }

    $(".page-wrapper").off("scroll").scroll(function(){
        //控制首页顶部显示，与客户端交互
        reqrolloffset();
        var scrollTop = $(".page-wrapper").scrollTop();
        var scrollHeight = $(".more-page").height() + $(".header").height();//总高度
        var screenHeight = $("body").height();//屏幕高度
        if(scrollTop + screenHeight*2 >= scrollHeight){
            if(oVal.loadYWFlag && oVal.ywNextPage){
                console.log("加载数据");
                oVal.loadYWFlag = false;
                oVal.ywPageNum++;
                if(oVal.configData.THS_MZ_KEY || oVal.configData.THS_MZ_KEY == "0"){
                    //旧版资讯推荐
                    getOldYaoWenOtherInfo();
                }else{
                    getYaoWenOtherInfo()
                }
            }
        }
    })
</script>
</html>